var app = new Vue({
	el: '#app',
	mixins: [isLogin, page],
	components: {
		searchHeader,
		login,
	},
	data: {
		keyWord: '', //搜索关键词
		searchData: [], //搜索数据
		TotalCount: '', //总条数
	},
	methods: {
		//一进来获取搜索数据
		getNewsList: function(currentPage) {
			var _this = this;
			if(!this.keyWord) {
				var href = location.href;
				var keyWord = decodeURI(xq.getQueryString('keyWord', href));
				this.keyWord = keyWord;
			}
			if(currentPage) {
				currentPage = currentPage;
			} else {
				currentPage = 1;
			}
			this.onePageCount = 10;
			var method = 'BigData/GetSearch';
			var param = {
				Keyword: this.keyWord,
				PageSize: this.onePageCount,
				PageIndex: currentPage,
			};
			xq.getUrl(method, param, function(res) {
				if(res.data) {
					var data = res.data;
					if(xq.device == 1) {
						if(!_this.totalPage) {
							_this.totalPage = Math.ceil(data.TotalCount / _this.onePageCount);
//							_this.TotalCount = data.TotalCount;
							_this.initPage();
						}
						_this.TotalCount = data.TotalCount;
						_this.searchData = data.ListEntity;
					} else {
						_this.totalPage = Math.ceil(data.TotalCount / _this.onePageCount);
						_this.TotalCount = data.TotalCount;
						for(var i = 0;i<data.ListEntity.length;i++){
							_this.searchData.push(data.ListEntity[i]);
						}
					}

				}
			});
		},
		//上拉加载更多手机端
		//		loadMore
		//点击搜索按钮
		clickSearchBtn: function() {
			this.getNewsList();
		},
		//点击分类关键字
		clickClassWord: function(event) {
			var keyWord = $(event.target).html();
			this.keyWord = keyWord;
		},
		//跳转到对应的详情
		toDetail:function(type,id){
			if(type){
				var Url = null;
				type = parseInt(type);
				switch(type){
					case 1:
						Url = 'newsDetail.html?id=';
						break;
					case 2:
						Url = 'bids.html?id=';
						break;
					case 3:
						Url = 'compCard.html?id=';
						break;
				}
				Url = Url + id;
				window.open(Url,'_blank');
			}
		},
	},
	mounted: function() {
		var _this = this;
		if(xq.device == 1) {
			this.getNewsList();
		} else {
			var currentPage = 1;
			xq.loadMore(function() {
				currentPage++;
				if(currentPage <= _this.totalPage) {
					_this.getNewsList(currentPage);
				} else {
					xq.toast1('没有更多数据了哦');
				}
			})
		}
	},
	updated: function() {

	}
})